import 'dart:convert';

import 'package:bot_toast/bot_toast.dart';
import 'package:exams_app/net/Address.dart';
import 'package:exams_app/net/DioManager.dart';
import 'package:exams_app/net/persisten_storage.dart';
import 'package:get/get.dart';
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:web_socket_channel/status.dart' as status;
import 'dart:convert' as convert;


class LiveLogic extends GetxController{

  RxMap json;

  var name = ''.obs;
  var uid = 0.obs;

  var u_count = 0.obs;

  WebSocketChannel channel;

  requestDataWithLive(var liveid)async{

    var  params = {
      'live_id':liveid,
    };

    String result = await DioUtils(url: await PersistentStorage().getStorage('urlStr')).
    postModel(Address.getattt,function_name:'_api_one',model:'res.live',params:params );
    Map _json = jsonDecode(result);
    json = _json.obs;

    print('================= ${result}');

    update();

  }


  /// 直播列表
  ///

  var liveList = List();

  requestDataWithListLive({var page = 0})async{

    var  params = {
      'page':page,
      'limit':'10',
    };

    String result = await DioUtils(url: await PersistentStorage().getStorage('urlStr')).
    postModel(Address.getattt,function_name:'_api_page',model:'res.live',params:params );
    Map json = jsonDecode(result);

    if(page == 0){

      // _esController.resetLoadState();
      liveList.clear();
      liveList.addAll(json['data']);
    }else{

      if(json['data'].length>0){
        // for(int i = 0;i<model.data.length;i++){
        //   model.data[i].isSelect = false;
        // }

        liveList.addAll(json['data']);
      }else if(json['data'].length <= 0){
        // _esController.finishLoad(success: true,noMore: true);
        // _esController.finishLoad(success: true, noMore: true);
        // COToast.show('暂无更多',a: ToastGravity.BOTTOM);
        // Toast.toast(context,msg: '暂无更多',position:ToastPostion.bottom);
        BotToast.showText(text: '暂无更多');
      }
    }

    update();
  }


}